home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 2099 / 2099.xpi / chrome / javascript.js < prev    next >
Text File  |  2006-04-04  |  5KB  |  190 lines

  1.  
  2. function Repaginator()
  3. {
  4. }
  5.  
  6. Repaginator.prototype.enabled = false;
  7. Repaginator.prototype.pagecounter = 0;
  8. Repaginator.prototype.prevPage = '';
  9.  
  10. // Get last item in a container
  11. Repaginator.prototype.getLast = function(container)
  12. {
  13.     var item =  container.iterateNext();
  14.     var temp = item;
  15.     while(temp != null)
  16.     {
  17.         temp = container.iterateNext();
  18.         if(temp != null)
  19.         {
  20.             item = temp;
  21.         }
  22.     }    
  23.  
  24.     return item;
  25. };
  26.  
  27. Repaginator.prototype.blast = function(win)
  28. {    
  29.     try
  30.     {
  31.         var xresult = win.document
  32.                 .evaluate(
  33.                     this.query,
  34.                     win.document,null,0,null);
  35.         var node = this.getLast(xresult);
  36.         if(node != null)
  37.         {
  38.             win.document.body.setAttribute('repagination','isOn');
  39.  
  40.             var iframe = win.document.createElement('iframe');
  41.             this.iframe = iframe;
  42.             iframe.style.display='none';
  43.             iframe.setAttribute('src',node.href);
  44.             repagination.RegisterRepaginator(this);
  45.             iframe.addEventListener('load',function(event)
  46.             {                    
  47.                 repagination.GetRepaginator(this).loadNext(this);
  48.             },true);
  49.             win.document.body.setAttribute('repagination','isOn');
  50.             win.document.body.appendChild(iframe);
  51.         }
  52.         else
  53.         {
  54.             win.document.body.setAttribute('repagination','isOff');
  55.         }
  56.     }
  57.     catch(ex)
  58.     {
  59.         win.document.body.setAttribute('repagination','isOff');
  60.     }
  61. };
  62. Repaginator.prototype.beforeNum =    Repaginator.prototype.afterNum =
  63. Repaginator.prototype.numStr = '';
  64. Repaginator.prototype.isSelect = true;
  65.  
  66. Repaginator.prototype.loadNextThunk = function()
  67. {
  68.     myRepaginator.loadNext(myRepaginator.iframe);
  69. };
  70.  
  71. Repaginator.prototype.increment = function()
  72. {
  73.     this.query = this.query.replace(new RegExp(this.numberToIncrement, 'g'), Number(this.numberToIncrement) + 1);
  74.     this.numberToIncrement++;
  75. };
  76.  
  77. /// Append all children of source to target
  78. Repaginator.prototype.AppendChildren = function(source, target)
  79. {
  80.     //alert(source);
  81.     //alert(source.firstChild);
  82.     for (var child = source.firstChild; child != null; child = child.nextSibling)
  83.     {
  84.         //alert(child);
  85.         target.appendChild(child.cloneNode(true));
  86.     }
  87. };
  88.  
  89. Repaginator.prototype.loadNext = function(element)
  90. {
  91.     if (this.prevIframe)
  92.         this.prevIframe.parentNode.removeChild(this.prevIframe);
  93.     if (!this.slideshow) 
  94.         this.prevIframe = this.iframe;
  95.  
  96.     if(element.ownerDocument.body.getAttribute('repagination') == 'isOn')
  97.     {
  98.         var doc = this.iframe.contentDocument;
  99.         this.pagecounter++;
  100.         if(this.slideshow)
  101.         {
  102.             element.ownerDocument.body.style.display = 'none';
  103.             var cloner = doc.body.cloneNode(true);
  104.             element.ownerDocument.documentElement.appendChild(cloner);
  105.             element.ownerDocument.body = cloner;
  106.             element.ownerDocument.body.setAttribute('repagination','isOn');
  107.         }
  108.         else
  109.         {
  110.             this.AppendChildren(doc.body, element.ownerDocument.body);
  111.             //element.ownerDocument.body.appendChild(doc.body.cloneNode(true));
  112.         }
  113.  
  114.         var savedQuery;
  115.         if (this.attemptToIncrement)
  116.         {
  117.             savedQuery = this.query;
  118.             this.increment();
  119.         }
  120.         else if (this.numberToIncrement != null)
  121.             this.increment();
  122.  
  123.         var xresult = doc
  124.             .evaluate(this.query,doc,null,0,null);
  125.  
  126.         var node = this.getLast(xresult);
  127.  
  128.         if (this.attemptToIncrement && (node == null || node.href == doc.location.href))
  129.         {
  130.             this.query = savedQuery;
  131.             this.numberToIncrement = null;
  132.  
  133.             var xresult = doc
  134.                 .evaluate(this.query,doc,null,0,null);
  135.             node = this.getLast(xresult);
  136.         }
  137.  
  138.         this.attemptToIncrement = false;
  139.  
  140.         if(node != null && (doc.location == null || node.href != doc.location.href))
  141.         {
  142.  
  143.             if(doc.location != null)
  144.             {
  145.                 this.prevPage = 
  146.                     doc.location.href;
  147.             }
  148.             if(
  149.                 (
  150.                 (this.nolimit == false) 
  151.                 && (this.pagecounter <
  152.                 this.pagelimit)
  153.                  ) 
  154.                 || this.nolimit == true
  155.             )
  156.             {
  157.                 var niframe = element.ownerDocument.createElement('iframe');
  158.                 this.iframe = niframe;
  159.                 niframe.style.display='none';
  160.                 niframe.setAttribute('src',node.href);
  161.                 repagination.RegisterRepaginator(this);
  162.                 niframe.addEventListener('load',function()
  163.                 {
  164.                     var repaginator = repagination.GetRepaginator(this);
  165.                     if(repaginator.slideshow)
  166.                     {
  167.                         myRepaginator = repaginator;
  168.                         var timeout = setTimeout(repaginator.loadNextThunk, repaginator.seconds*1000);
  169.                     }
  170.                     else
  171.                     {
  172.                         repaginator.loadNext(this);
  173.                     }
  174.                 },true);
  175.                 element.ownerDocument.body.appendChild(niframe);
  176.             }
  177.             else
  178.             {
  179.                 element.ownerDocument.body.setAttribute('repagination','isOff');
  180.             
  181.             }
  182.  
  183.         }
  184.         else
  185.         {
  186.             element.ownerDocument.body.setAttribute('repagination','isOff');
  187.         }
  188.     }
  189. };
  190.